package org.mspring.mlog.web.module.web.ucenter.admin;

import java.util.ArrayList;
import java.util.List;

import org.mspring.mlog.web.module.web.ucenter.UCenter_AbstractWidget;
import org.mspring.mlog.web.support.Link;
import org.mspring.platform.utils.StringUtils;
import org.springframework.ui.Model;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月10日
 */
public class Abstract_UCenterAdminWidget extends UCenter_AbstractWidget {

    protected String error(Model model, String title, String message, String... navs) {
        // TODO Auto-generated method stub
        List<Link> links = new ArrayList<Link>();
        if (navs != null && navs.length > 0) {
            for (String nav : navs) {
                if (!StringUtils.isBlank(nav)) {
                    String[] strs = StringUtils.split(nav, "||");
                    if (strs.length == 1) {
                        links.add(new Link(strs[0], "javascript:history.go(-1);"));
                    } else if (strs.length == 2) {
                        links.add(new Link(strs[0], strs[1]));
                    } else if (strs.length == 3) {
                        links.add(new Link(strs[0], strs[1], strs[2]));
                    }
                }
            }
        }
        else {
            links.add(new Link("返回", "javascript:history.go(-1);"));
        }
        model.addAttribute("links", links);
        model.addAttribute("title", StringUtils.isBlank(title) ? "系统提示" : title);
        model.addAttribute("message", message);
        model.addAttribute("type", "error");
        return "skin:/ucenter/admin/prompt";
    }

    protected String success(Model model, String title, String message, String... navs) {
        List<Link> links = new ArrayList<Link>();
        if (navs != null && navs.length > 0) {
            for (String nav : navs) {
                if (!StringUtils.isBlank(nav)) {
                    String[] strs = StringUtils.split("||");
                    if (strs.length == 1) {
                        links.add(new Link(strs[0], "javascript:history.go(-1);"));
                    } else if (strs.length == 2) {
                        links.add(new Link(strs[0], StringUtils.isBlank(strs[1]) ? "javascript:history.go(-1);" : strs[1]));
                    } else if (strs.length == 3) {
                        links.add(new Link(strs[0], StringUtils.isBlank(strs[1]) ? "javascript:history.go(-1);" : strs[1], strs[2]));
                    }
                }
            }
        }
        else {
            links.add(new Link("返回", "javascript:history.go(-1);"));
        }
        model.addAttribute("links", links);
        model.addAttribute("title", StringUtils.isBlank(title) ? "系统提示" : title);
        model.addAttribute("message", message);
        model.addAttribute("type", "success");
        return "skin:/ucenter/admin/prompt";
    }
}
